package utils

type Number interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

// SlicesSum  求和
func SlicesSum[T Number](s []T) T {
	if len(s) == 0 {
		return T(0)
	}

	for _, v := range s {
		s[0] += v
	}

	return s[0]
}

// SlicesAvg 求平均
func SlicesAvg[T Number](s []T) float64 {
	if len(s) == 0 {
		return 0.0
	}

	for _, v := range s {
		s[0] += v
	}

	return float64(s[0]) / float64(len(s))
}
